<?php


namespace App\Transformers\Store;


use App\Models\IntegralProduct;
use App\Models\ProductAttrResult;
use App\Models\StoreCombination;
use App\Transformers\MerchantRegistersTransformer;
use App\Transformers\Product\ProductAttrResultTransformer;
use App\Transformers\Product\ProductAttrTransformer;
use App\Transformers\Product\ProductTransformer;
use League\Fractal\TransformerAbstract;

class IntegralProductTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['product','merchantRegister'];

    public function transform(IntegralProduct $data)
    {
        return [
            'id' => $data->id,
            'product_id' =>$data->product_id ?? "",
            'merchant_id' =>$data->merchant_id ?? "",
            'recommend_image' =>$data->recommend_image ?? "",
            'recommend_image_url' =>$data->recommend_image ?? "",
            'title' =>$data->title ?? "",
            'rotation_chart' =>$data->rotation_chart ?? "",
            'shel_status' =>$data->shel_status ?? "",
            'description' =>$data->description ?? "",
            'unit_name' =>$data->unit_name ?? "",
            'integral' =>$data->integral ?? "",
            'sort' =>$data->sort ?? "",
            'sales' =>$data->sales ?? "",
            'stock' =>$data->stock ?? "",
            'postage' =>$data->postage ?? "",
            'browse' =>$data->browse ?? "",
            'weight' =>$data->weight ?? "",
            'volume' =>$data->volume ?? "",
            'num' =>$data->num ?? "",
            'once_num' =>$data->once_num ?? "",
            'quota' =>$data->quota ?? "",
            'quota_show' =>$data->quota_show ?? "",
            'is_recommend' =>$data->is_recommend ?? "",
            'merchant_use' =>$data->merchant_use ?? "",
            'deleted_at' => $data->deleted_at ? $data->deleted_at->format("Y-m-d H:i:s") : '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'att_r' => $data->att_r ?? '',
        ];
    }

    /**
     *额外包含商品数据
     */

    public function includeProduct(IntegralProduct $integralProduct)
    {
        return $this->item($integralProduct->product, new ProductTransformer());
    }

    /**
     *额外包含商户信息
     */

    public function includeMerchantRegister(IntegralProduct $integralProduct)
    {
        return $this->item($integralProduct->merchantRegister, new MerchantRegistersTransformer());
    }

}
